﻿using Basic.Redis;
using Basic.Redis.Configurations;
using Basic.Redis.Providers.StackExchange;

namespace Microsoft.Extensions.DependencyInjection;

public static class ServiceCollectionExtension
{
    public static IServiceCollection AddBasicRedis(this IServiceCollection services, IConfigurationSection redisSection)
    {
        services.Configure<RedisOptions>(redisSection);
        /* StackExchange.Redis 对象 */
        services.AddSingleton<DefaultDatabaseProvider>();

        RedisOptions redisConfig = redisSection.Get<RedisOptions>();
        services.RegisterSerialization(redisConfig.SerializerName);
        services.AddSingleton<IRedisProvider, DefaultRedisProvider>();
        return services;
    }

}